<admintpl file="header" />
<style type="text/css">
.pic-list li {
	margin-bottom: 5px;
}
</style>
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('AdminSale/index')}">消费机构信息</a></li>
			<li class="active"><a href="{:U('AdminSale/add',array('id'=>empty($item['id'])?'':$item['id']))}" target="_self">添加消费机构</a></li>
		</ul>
		<form action="{:U('AdminSale/add_post')}" method="post" class="form-horizontal js-ajax-forms" enctype="multipart/form-data">
			<div class="row-fluid">
				<div class="span9">
					<table class="table table-bordered">
						<tr>
							<th>上级消费机构<span class="form-required">*</span></th>
							<td>
							<select name="sale_manager_id" style="margin:0px;">
								<option value="">请选择</option>
								<foreach name="sale_manager_list" item="sitem">
									<option value="{$sitem['id']}" <if condition="$item['sale_manager_id'] == $sitem['id']">selected</if>>{$sitem.sale_manage_name}</option>
								</foreach>
							</select>
							</td>
						</tr>
						<tr>
							<th>消费机构名称<span class="form-required">*</span></th>
							<td><input type="text" name="sale_name" id="sale_name" value="{$item.sale_name}" style="width: 400px" placeholder="请输入消费机构名称"> </td>
						</tr>
						<tr>
							<th>积分满赠线<span class="form-required">*</span></th>
							<td><input type="text" name="point_line" id="point_line" value="{$item.point_line}" style="width: 400px" placeholder="每满多少金额赠送1积分"> </td>
						</tr>
						<tr>
							<th>封面图<span class="form-required">*</span></th>
							<td><input type="text" name="cover" id="js-cover-image" value="{$item.cover}"> <a href="javascript:upload_one_image('图片上传','#js-cover-image');">上传图片</a> </td>
						</tr>
						<tr>
							<th>联系电话<span class="form-required">*</span></th>
							<td><input type="text" name="telphone" id="telphone" value="{$item.telphone}" style="width: 400px" placeholder=""> </td>
						</tr>
						<tr>
							<th>定位地址<span class="form-required">*</span></th>
							<td>
								<input name="address" id="search_in" value="{$item.address|default=宁夏回族自治区银川市}" type="text" class="form-control" placeholder="">
								<input name="lng" id="lng" value="{$item.lng|default='106.231008'}" type="hidden">
								<input name="lat" id="lat" value="{$item.lat|default='38.48763'}" type="hidden">
							</td>
						</tr>
						<tr>
							<th></th>
							<td>
								<div class="box-body amap-container" id="allmap" style="height: 500px; margin: 10px 10px 20px 20px; position: relative; background: rgb(252, 249, 242);">
								</div>
							</td>
						</tr>
                    </table>
				</div>

			</div>
			<div class="form-actions">
                <input type="hidden" name="id" value="{$item.id}"/>
				<button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
				<a class="btn" href="{:U('AdminSale/index')}">返回</a>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=420b64925f5eb604b09b181d31cec54b"></script>
	<script crossorigin="anonymous" id="amap_plus_js" src="https://webapi.amap.com/maps/modules?v=1.4.6&key=420b64925f5eb604b09b181d31cec54b&vrs=1536672475634&m=mouse,vectorlayer,overlay,wgl,sync" type="text/javascript"></script>
	<script type="text/javascript" src="//cache.amap.com/lbs/static/addToolbar.js"></script>
	<script type="text/javascript" src="https://webapi.amap.com/demos/js/liteToolbar.js"></script>
	<script src="//webapi.amap.com/ui/1.0/main.js"></script>
	<!-- <link rel="stylesheet" href="//cache.amap.com/lbs/static/main1119.css"> -->
	<script type="text/javascript" charset="utf-8" async="" data-requirecontext="amap-ui-1.0.11" data-requiremodule="ui/misc/PoiPicker" src="https://webapi.amap.com/ui/1.0/ui/misc/PoiPicker.js?v=1.0.11&mt=ui&key=9595b136feb2d411849894f3090a9a03"></script>
	<script type="text/javascript" charset="utf-8" async="" data-requirecontext="amap-ui-1.0.11" data-requiremodule="https://webapi.amap.com/count?type=UIInit&k=9595b136feb2d411849894f3090a9a03" src="https://webapi.amap.com/count?type=UIInit&k=9595b136feb2d411849894f3090a9a03&v=1.0.11"></script>
	<script type="text/javascript">

		var lng = $("input[name='lng']").val();
		var lat = $("input[name='lat']").val();
		// var lng='106.231008',lat='38.48763';
		var provice='',city='',county='';

		//创建地图函数：
		var map = new AMap.Map("allmap",{level:10});//在百度地图容器中创建一个地图
		if(lng!='' && lat!=''){
		    map.setZoomAndCenter(10, [lng, lat]);
		    var marker = new AMap.Marker({
		        map: map,
		        position: [lng, lat]
		    });

		}else{
		    map.setCity('银川');
		    var marker = new AMap.Marker({
		        position: map.getCenter()
		    });
		}
		marker.setMap(map);


		AMapUI.loadUI(['misc/PoiPicker'], function(PoiPicker) {

		    var poiPicker = new PoiPicker({
		        //city:'北京',
		        input: 'search_in'
		    });

		    //初始化poiPicker
		    poiPickerReady(poiPicker);
		});

		map.plugin(["AMap.Geocoder"]);

		//为地图注册click事件获取鼠标点击出的经纬度坐标
		map.on('click', function(e) {
		    var geocoder = new AMap.Geocoder({
		        radius: 1000,
		        extensions: "all"
		    });
		    lng=e.lnglat.getLng();
		    lat=e.lnglat.getLat();
		    console.log(lng,lat);
		    map.setZoomAndCenter(14, [e.lnglat.getLng(), e.lnglat.getLat()]);
		    marker.setPosition(e.lnglat);
		    geocoder.getAddress(e.lnglat, function(status, result) {
		        if (status === 'complete' && result.info === 'OK') {
		            geocoder_CallBack(result);
		        }
		    });
		});

		function poiPickerReady(poiPicker) {
		    window.poiPicker = poiPicker;
		    //选取了某个POI
		    poiPicker.on('poiPicked', function(poiResult) {
		        var source = poiResult.source,
		                poi = poiResult.item;
		        lng=poi.location.lng;
		        lat=poi.location.lat;

		        marker.setMap(map);
		        marker.setPosition(poi.location);
		        map.setCenter(marker.getPosition());
		        map.setZoom(15);
		        $("#search_in").val(poi.district+' '+poi.address);
		        $("input[name='lng']").val(lng);
		        $("input[name='lat']").val(lat);
		    });

		}
		function geocoder_CallBack(data) {
		    var address = data.regeocode.formattedAddress; //返回地址描述
		    provice=data.regeocode.addressComponent.province;
		    city=data.regeocode.addressComponent.city;
		    county=data.regeocode.addressComponent.district;

		    $("#search_in").val(address);
		    $("input[name='lng']").val(lng);
		    $("input[name='lat']").val(lat);
		}


	</script>
	</body>
</html>